package com.cyh.service.impl;

import com.cyh.dao.UserDao;
import com.cyh.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserServiceImpl implements UserService {
    private UserDao userDao2 = null;

    //如果构造函数的参数是基本类型，不要放到构造函数里面，直接属性，然后实现set方法 --- 看 UserDaoImpl 类
    public UserServiceImpl(){
        System.out.println("UserServiceImpl无参构造...");
    }

    public UserServiceImpl(UserDao userDao2) {
        System.out.println("UserServiceImpl有参构造....");
        this.userDao2 = userDao2;
    }

    //创建对象方法二 配置文件中设置
    public void setUserDao2(UserDao userDao2){
        this.userDao2 = userDao2;
    }
    @Override
    public void save() {
        //创建对象方法一 直接新建
        /*ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserDao userDao = (UserDao) app.getBean("userDao");
        userDao.save();*/

        //创建对象方法二 配置文件中设置
        userDao2.save();
    }
}
